var e = getApp();

Page({
    data: {
        customBalance: "",
        showRejectPopup: !1,
        showGiftPopup: !1,
        showSuccessPopup: !1,
        rid: "",
        redpack_img: "",
        redpack_name: "",
        redpack_list: [],
        show_button: !1,
        total: 0,
        page: 1,
        loading: !1,
        finished: !1,
        receivedSucceed: {}
    },
    onLoad: function(e) {
        try {
            var a = wx.getStorageSync("yz_basic_info");
            this.setData({
                customBalance: a.balance.balance ? a.balance.balance : "余额"
            });
        } catch (e) {
            console.log(e);
        }
    },
    onShow: function() {
        this.init(), this.getData();
    },
    init: function() {
        this.setData({
            showRejectPopup: !1,
            showGiftPopup: !1,
            showSuccessPopup: !1,
            rid: "",
            redpack_img: "",
            redpack_name: "",
            redpack_list: [],
            show_button: !1,
            total: 0,
            page: 1,
            loading: !1,
            finished: !1
        });
    },
    goHome: function() {
        wx.navigateTo({
            url: "/packageG/index/index"
        });
    },
    getData: function() {
        var a = this, t = e.getNetAddresss("plugin.redpack-user.frontend.homePage.index");
        e._getNetWork({
            url: t,
            success: function(e) {
                if (1 === e.data.result) {
                    var t = e.data.data, s = !1;
                    (a.data.page >= t.redpack_list.last_page || t.redpack_list.data.length < t.redpack_list.per_page) && (s = !0), 
                    a.setData({
                        finished: s,
                        page: ++a.data.page,
                        show_button: t.show_button,
                        redpack_list: t.redpack_list.data
                    });
                } else wx.showToast({
                    title: e.data.msg
                });
            }
        });
    },
    getMoreData: function() {
        var a = this;
        if (!this.data.finished) {
            var t = e.getNetAddresss("plugin.redpack-user.frontend.homePage.index");
            wx.showLoading({
                title: "加载中"
            }), e._getNetWork({
                url: t,
                data: {
                    page: this.data.page
                },
                success: function(e) {
                    if (wx.hideLoading(), 1 === e.data.result) {
                        var t = e.data.data, s = !1, o = a.data.redpack_list.concat(t.redpack_list.data);
                        (a.data.page >= t.redpack_list.last_page || t.redpack_list.data.length < t.redpack_list.per_page) && (s = !0), 
                        a.setData({
                            redpack_list: o,
                            finished: s,
                            page: ++a.data.page
                        });
                    } else wx.showToast({
                        title: e.data.msg
                    });
                },
                fail: function() {
                    wx.hideLoading();
                }
            });
        }
    },
    receiveGift: function(e) {
        var a = e.currentTarget.dataset.redpack;
        this.setData({
            rid: a.id,
            redpack_img: a.thumb,
            redpack_name: a.member.nickname,
            showGiftPopup: !0
        });
    },
    closePopup: function() {
        this.setData({
            showGiftPopup: !1
        });
    },
    openGift: function() {
        var a = this, t = e.getNetAddresss("plugin.redpack-user.frontend.receive.index");
        e._getNetWork({
            url: t,
            data: {
                rid: this.data.rid
            },
            success: function(e) {
                1 === e.data.result ? a.setData({
                    receivedSucceed: e.data.data,
                    showGiftPopup: !1,
                    showSuccessPopup: !0
                }) : a.setData({
                    showRejectPopup: !0,
                    showGiftPopup: !1,
                    rejectMess: e.data.msg
                });
            }
        });
    },
    confirm: function() {
        this.setData({
            showSuccessPopup: !1,
            page: 1
        }), this.getData();
    },
    hideRejectPopup: function() {
        this.setData({
            showRejectPopup: !1
        });
    },
    onReachBottom: function() {
        this.getMoreData();
    },
    goPersonRedIssue: function() {
        wx.navigateTo({
            url: "/packageI/personRed/personRedIssue/personRedIssue"
        });
    },
    goPersonList: function() {
        wx.navigateTo({
            url: "/packageI/personRed/personRedList/personRedList"
        });
    },
    goPersonRedRecord: function(e) {
        var a = e.currentTarget.dataset.rid;
        wx.navigateTo({
            url: "/packageI/personRed/personRedRecord/personRedRecord?rid=".concat(a)
        });
    }
});